package com.banyuan.lesson.网络编程;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;


/*
 * 1、控制台输入流；
 * 2、一直聊；
 * */
public class Client {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            //会连接服务端；
            Socket socket = new Socket("localhost", 8080);
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String msg = br.readLine();
            System.out.println(msg);
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            out.println("服务器你好，我已收到！");

            new Thread(() -> {
                while (true) out.println(sc.nextLine());
            }).start();

            while (true) {
                System.out.println(br.readLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
